<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>异常任务</title>
</head>
<body>
<section>
    <div>
        <div class="layui-card">
            <div class="adp-content">
                <form id="queryForm"></form>
                <table id="queryTable"></table>
            </div>
        </div>
    </div>
</section>
<div style="width: 600px;display: none;" id="mergeFormDiv">
    <form action="" method="post" id="mergeForm" class="adp-center"></form>
</div>
</body>
</html>
<script src="../static/adp/import.js"></script>

<script type="text/html" id="OPERATION_ROW_TPL">
    <a class="layui-btn layui-btn-sm" lay-event="confirm"> <i class="layui-icon layui-icon-edit"></i>人工处理异常</a>
</script>

<script type="text/javascript">
    var queryform = $("#queryForm").adpForm({
        elem: [{type: "text", label: "任务编号", name: "taskId", placeholder: "请输入任务编号"},
            {type: "text", label: "料框编号", name: "containerId", placeholder: "请输入料框遍号"},
            {type: "date", label: "按日志查询 从", name: "startDate", placeholder: "请输入关键字"},
            {type: "date", label: "至", name: "endDate", placeholder: "请输入关键字"},
            {type: "text", label: "标签编号", name: "epcId", placeholder: "请输入标签编号"}
        ],
        button: [{type: "submit", label: "查询", method: "query", icon: 'query'}, {type: "submit", label: "重置"}],
        methods: {
            query: function query() {
                queryTable.reload(this.data());
            }
        }
    });
    var mergeForm = $("#mergeForm").adpForm({
        layout: 'vertical',
        elem: [
            {type: "text", label: "详情", name: "details"},
            {type: "hidden", name: "id"}
        ],
        button: [
            {type: "submit", label: "保存", method: "submit"},
            {type: "reset", label: "重置"}
        ],
        methods: {
            submit: function submit(data) {
                layer.confirm('确认将该任务标记为完成?', function (index) {
                    console.log(data);
                    SV("Task")("confirmErrorTask")({id: data.id, details: data.details});
                    queryTable.reload(queryform.data());
                    layer.close(index);
                });
            }
        }

    });

    var queryTable = $("#queryTable").adpTable({
        url: '../rs/Task/listErrorTask',
        where: queryform.data(),
        cols: [[
            {field: 'id', title: 'ID', type: 'checkbox', width: 30, sort: true, fixed: 'left'},
            {field: 'taskId', title: '任务编号', width: 180},
            {field: 'containerId', title: '料框编号', width: 180},
            {field: 'epcId', title: 'epc标签号', width: 180},
            {field: 'status', title: '任务状态', width: 180},
            {field: 'taskFrom', title: '任务来源', width: 180},
            {field: 'date', title: '任务日期', width: 180},
            {fixed: 'right', title: '操作', width: 200, align: 'center', toolbar: '#OPERATION_ROW_TPL'}
        ]],
        methods: {
            confirm: function confirm(data, tr) {
                $("#mergeFormDiv").open("编辑任务");
                mergeForm.reset();
                mergeForm.data(data);
            }
        }
    });

    function addEntity() {
        return $("#mergeFormDiv").open("添加任务", {
            success: function success() {
                return mergeForm.reset();
            }
        });
    };

    function deleteAllEntity(arr) {
        var _queryTable$checkStat = queryTable.checkStatus(),
            data = _queryTable$checkStat.data;
        var ids = new Array();
        $.each(data, function (n, value) {
            ids.push(value.id);
        });
        layer.confirm('真的删除行么', function (index) {
            Deferred("Task")("delete")({
                "ids": ids
            }).then(function () {
                queryTable.reload(queryform.data());
                layer.close(index);
            });
        });
    };
</script>